<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            line-height: 200px;
           
            text-align: center;
        }
    </style>
</head>
<body>
<div id="mydiv" style="width: 200px;height: 200px;background-color: palevioletred;margin:100px auto;">点击变色</div>
    <script>
        var isclicked=false;
        var mydiv=document.getElementById("mydiv");
        mydiv.onclick=function(){
            if(!isclicked){
           mydiv.style.backgroundColor="#FFC0CB";
           isclicked=true;}
           else{
            mydiv.style.backgroundColor="#800080"
            isclicked=false;;
           }
        }
    </script>
</body>
</html>
</body>
</html>